ARG PHP_IMAGE
FROM $PHP_IMAGE

ARG PHP_VERSION
ARG TZ
ARG IMAGE_NAME
ARG CONTAINER_PACKAGE_URL
ARG PHP_EXTENSIONS
ARG WWW_DATA_UID

RUN if [ $CONTAINER_PACKAGE_URL ] ; then sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories ; fi

ADD ./extensions/install-php-extensions  /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions

COPY ./extensions /tmp/extensions
WORKDIR /tmp/extensions
RUN chmod +x install.sh \
    && chmod +x install-composer.sh \
    && sh install.sh \
    && sh install-composer.sh \
    && rm -rf /tmp/extensions

RUN apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
    && echo "$TZ" > /etc/timezone

RUN apk --no-cache add shadow && usermod -u ${WWW_DATA_UID} www-data && groupmod -g ${WWW_DATA_UID} www-data

WORKDIR /var/www/html